﻿#include "slic.h"
#include "extractorLocationVector.h"
#include "extractorShapeVector.h"
#include "extractorMultiScaleDenseSiftVector.h"
#include "extractorBoundaryCenterVector.h"
#include "extractorVolumneVector.h"
#include "svmTrainer.h"
#include "colorVocabulary.h"
#include "extractorSuperpixelDataSet.h"
#include "localSiftVocabulary.h"
#include <opencv2/features2d/features2d.hpp>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <vl/generic.h>
#include "configurationParameters.h"
#include "utilitiesFunction.h"

int main() {
	/*
    // Load the image and convert to Lab colour space.
    IplImage *image = cvLoadImage("flower/image_0059.jpg");
    IplImage *lab_image = cvCloneImage(image);
	Mat t_image = cvCloneImage(image);
	//Mat tt_image = cvCloneImage(image);
	Mat label_image;
    //cvCvtColor(image, lab_image, CV_BGR2Lab);
	Grabcut grabCut;
    
	grabCut.segment(lab_image, configurationParameters::gcRatioCenter() );

	// END

    // Yield the number of superpixels and weight-factors from the user.

    int w = image->width, h = image->height;
    int nr_superpixels = 180; //250;// 100 // 200; // Maximum K  cluster
    int nc = 100; //100; // 40

    double step = sqrt((w * h) / (double) nr_superpixels); // S = sqrt(N/K) , S: size of superpixels
    
	// END

    // Perform the SLIC superpixel algorithm.

    Slic slic;
    slic.generate_superpixels(lab_image, step, nc);
    slic.create_connectivity(lab_image);
    
	// END

    // Display the contours and show the result.

    slic.display_contours(image, CV_RGB(255,0,0));

	label_image = slic.label_fg(0.6, grabCut.loadMask());
	IplImage* image2=cvCloneImage(&(IplImage)label_image);
	slic.display_contours(image2, CV_RGB(255,0,0));

	Mat result = grabCut.loadMask();
	t_image.copyTo(t_image, result); // bg pixels not copied

	namedWindow("Original");
	namedWindow("Foreground");
	namedWindow("Grabcut");
	//namedWindow("Lab_Image");
	cvShowImage("Original", image);
	cvShowImage("Foreground", image2);
	//cvShowImage("Lab_Image",lab_image);
	imshow("Grabcut", result);
	*/
	/******************** end ******************/

	/* Extractor Location Vector  */

	//extractorLocationVector extractLocationVector("flower/lena.jpg", slic);

	/******************** end ******************/

	/* Extractor shape Vector  */

	//extractorShapeVector extractShapeVector(image,"flower/lena.jpg", slic);

	/******************** end ******************/

	/* Extractor Volumne vector */

	//extractorVolumneVector extract_volumne_vector("flower/lena.jpg", slic);

	/******************** end ******************/

	/* Extractor extractorBoundaryCenter Vector */

	//extractorBoundaryCenterVector extract_BoundaryCenter_vector("flower/lena.jpg", slic);

	/******************** end ******************/

	 /* External Multi-scale Dense Sfit for all superpixels on image */

	//siftVocabulary siftvoca(configurationParameters::sizeSiftVocabulary(), configurationParameters::sizeSiftSample());
	//siftvoca.getSampleOnTrainingSet("flower/","image",1,80);
	//siftvoca.generateDictionary();
	//Mat dictionary = siftvoca.getDictionary();
	//extractorMultiScaleDenseSiftVector sift_extractor(t_image,"image_0027.jpg",slic,dictionary);
	
	/******************** end ******************/

	 /* Internal Multi-scale Dense Sfit for all superpixels on image */
	/* You should use this feature for svm trainer */

	/*
	localSiftVocabulary local_sift_voca(configurationParameters::sizeSiftVocabulary(),"image_0059.jpg",t_image);
	local_sift_voca.generateDictionary();
	Mat dictionary = local_sift_voca.getDictionary();
	extractorMultiScaleDenseSiftVector sift_extractor(t_image,"image_0027.jpg", slic,dictionary);
	vector<multiScaleDenseSiftVector> list_sift_vector_for_all_superpixel_on_image = sift_extractor.getListVector();
	*/

	/******************** end ******************/

	extractorSuperpixelDataSet extractorSuperpixelDataset("flower/", "image", 1, 5);
	//svmTrainer SVM(extractorSuperpixelDataset.getSampleFeatureVector(), extractorSuperpixelDataset.getLabel());

	int stop;
	cin >> stop;
	
	waitKey(0);
	
}
